// 复杂的类型体操，类型体操中有类型递归
type CollectionTypes = Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any>
type BaseTypes = string | number | boolean
interface RefUnwrapBailTypes { }
interface Ref<T = any> { value: T; }

type UnwrapRef<T> = T extends Ref<infer V> ? UnwrapRefSimple<V> : UnwrapRefSimple<T>
type UnwrapRefSimple<T>=T extends
| Function
| CollectionTypes
| BaseTypes
| Ref
| RefUnwrapBailTypes[keyof RefUnwrapBailTypes]
? T
:T extends Array<any>
?{[K in keyof T]: UnwrapRefSimple<T[K]> }
:T extends object
? Unwrappedobject<T>
: T



type Expand<T> = T extends object ? { [K in keyof T]: T[K] } : T

// Unwrappedobject还有嵌套UnwrapRef<T[P]>，嵌套太深。TypeScript 在显示复杂映射类型时，默认保留类型别名。
// type Unwrappedobject<T> = { [P in keyof T]: UnwrapRef<T[P]> }  // type urf = Unwrappedobject<{ name: Ref<string>; age: Ref<number>; }>

// 当使用条件类型时，TypeScript可能更积极地展开映射类型，而不是保留类型别名。
// type Unwrappedobject<T> = Expand<{ [P in keyof T]: UnwrapRef<T[P]> }>
type Unwrappedobject<T> = T extends object ? { [P in keyof T]: UnwrapRef<T[P]> } : T  // type urf = { name: string, age: number }

let urf: UnwrapRef<{ name: Ref<string>, age: Ref<number> }> = { name: "张三", age: 18 }
let urf2: UnwrapRef<Ref<string>>

